import 'package:flutter/material.dart';
import 'package:flutter_project/components/MTFoodDetail.dart';

class MTFoodItem extends StatelessWidget {
  const MTFoodItem({Key? key, required this.foodItem}) : super(key: key);
  final Map<String, dynamic> foodItem;

  Widget getLeft() {
    return Container(
      margin: EdgeInsets.all(10),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(10),
        child: Image.network(
          foodItem["picture"],
          width: 100,
          height: 100,
          fit: BoxFit.cover,
        ),
      ),
    );
  }

  Widget getRight() {
    return Expanded(
        child: Padding(
            padding: EdgeInsets.only(top: 10, bottom: 10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  foodItem["name"],
                  style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
                ),
                Text(
                    '月销量${foodItem["month_saled"]} ${foodItem["like_ratio_desc"]}',
                    style:
                        TextStyle(fontWeight: FontWeight.w500, fontSize: 14)),
                Text(foodItem["price"].toString(),
                    style: TextStyle(
                        fontWeight: FontWeight.w600,
                        fontSize: 14,
                        color: Colors.amber))
              ],
            )));
  }

  Widget getChild() {
    return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
      getLeft(),
      getRight(),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        // Navigator.push(context,
        //     MaterialPageRoute(builder: (context) => const MTFoodDetail()));

        Navigator.pushNamed(context, '/detail');
      },
      child: getChild(),
    );
  }
}
